<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>信息管理</title>
<link rel="stylesheet" href="resources/bootstrap.min.css">  
<script src="resources/jquery.min.js"></script>
<script src="resources/bootstrap.min.js"></script>
<script src="resources/layer/layer.js"></script>
</head>
<body>
	<div class="jumbotron text-center" style="margin-bottom:0">
		<h3>公告管理列表</h3>
		<table class="table table-bordered table-hover">
        <caption>公告管理</caption>
	    <thead>
	        <tr class="text-c">
	        	<th class="text-center">复选</th>
	            <th class="text-center">编号</th>
	            <th class="text-center">标题</th>
	            <th class="text-center">内容</th>
	            <th class="text-center">时间</th>
	        </tr>
	    </thead>
	    <tbody>
	    	<c:forEach var="a" items="${list}">
               <tr>
   				  <td><input type="checkbox" name="id[]" value="${a.id}"/></td>
                  <td>${a.id}</td>
                  <td>${a.title}</td>
                  <td>${a.content}</td>
                  <td>${a.time}</td>         
                </tr>
             </c:forEach>
	    </tbody>
	</table>
	<button type="button" class="btn btn-warning pull-right" onclick="del()">批量删除</button>
	</div>
</body>
</html>
<script>
/* 批量删除 */
function del(){
	layer.confirm("您真的要删除选中的公告吗？",{
		btn:['确认删除','思考一下']
	},()=>{
		 let ids = $('input[name="id[]"]:checked');
	     // 删除的ID
	     let id = [];
	     // 循环
	     $.each(ids, (key, val) => {
	       // dom对象 转为 jquery对象 $(dom对象)
	       id.push(val.value);
	     });
	     if(id.length > 0){
	    	// 发起ajax
	    	$.ajax({
	    		url:"delete",
	    		data:{id},
	    		type:'POST'
	    	}).then(ret=>{
	    		if(ret=="success"){
	    			layer.msg("恭喜，删除成功！",{icon:6},()=>{
	    				location.reload();
	    			})
	    		}
	    		if(ret=="fail"){
	    			layer.msg("很遗憾，删除失败",{icon:5},()=>{
	    				location.reload();
	    			})
	    		}
	    	});
	     }else{
	    	 layer.msg("请选择要删除的公告！",{icon:0}) 
	     }
	});
}
</script>